package com.csx.orm.mybatis.controller;

import com.csx.orm.mybatis.entity.User;
import com.csx.orm.mybatis.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/mybatis")
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/getAllUsers")
    public List<User> getAllUsers() {
        return userService.getAllUsers();
    }

    @GetMapping("/getUserById/{id}")
    public User getUserById(@PathVariable Long id) {
        return userService.getUserById(id);
    }

    @PostMapping("/createUser")
    public String createUser(@RequestBody User user) {
        userService.createUser(user);
        return "createUser Success";
    }

    @PostMapping("/updateUser/{id}")
    public String updateUser(@PathVariable Long id, @RequestBody User user) {
        user.setId(id);
        userService.updateUser(user);
        return "updateUser Success";
    }

    @PostMapping("/deleteUser/{id}")
    public String deleteUser(@PathVariable Long id) {
        userService.deleteUser(id);
        return "deleteUser Success";
    }

    @PostMapping("/getUsersByCondition")
    public List<User> getUsersByCondition(@RequestBody User userCondition) {
        return userService.getUsersByCondition(userCondition);
    }

    @PostMapping("/getUsersUseTrim")
    public List<User> getUsersUseTrim(@RequestBody User user) {
        return userService.getUsersUseTrim(user);
    }

    @PostMapping("/getUsersUseChoose")
    public List<User> getUsersUseChoose(@RequestBody User user) {
        return userService.getUsersUseChoose(user);
    }

    @PostMapping("/getUsersUseForeach")
    public List<User> getUsersUseForeach(@RequestBody List<Long> ids) {
        return userService.getUsersUseForeach(ids);
    }

    @PostMapping("/getUsersUseBind")
    public List<User> getUsersUseBind(@RequestBody User user) {
        return userService.getUsersUseBind(user);
    }

    @GetMapping("/getUsersUseSql")
    public List<User> getUsersUseSql() {
        return userService.getUsersUseSql();
    }

    @PostMapping("/getUsersByConditionSql")
    public List<User> getUsersByConditionSql(@RequestBody User user) {
        return userService.getUsersByConditionSql(user);
    }

    @PostMapping("/updateUserUseSet")
    public void updateUserUseSet(@RequestBody User user) {
        userService.updateUserUseSet(user);
    }

    @PostMapping("/updateUserUseTrim")
    public void updateUserUseTrim(@RequestBody User user) {
        userService.updateUserUseTrim(user);
    }

    @GetMapping("/getUsersResultMapNoArgs")
    public List<User> getUsersResultMapNoArgs() {
        return userService.getUsersResultMapNoArgs();
    }


    @GetMapping("/getUsersResultMapArgs")
    public List<User> getUsersResultMapArgs() {
        return userService.getUsersResultMapArgs();
    }

    @GetMapping("/getUsersResultMapQuote")
    public List<User> getUsersResultMapQuote() {
        return userService.getUsersResultMapQuote();
    }

    @GetMapping("/getUserResultMapExtends")
    public List<User> getUserResultMapExtends() {
        return userService.getUserResultMapExtends();
    }

    @GetMapping("/getUserResultMapDiscriminator")
    public List<User> getUserResultMapDiscriminator() {

        return userService.getUserResultMapDiscriminator();
    }

    @GetMapping("/findAll")
    public List<User> findAll() {
        return userService.findAll();
    }

    @GetMapping("/findById")
    public User findById(@RequestParam("id") Long id) {
        return userService.findById(id);
    }

    @PostMapping("/findUsersByCondition")
    public List<User> findUsersByCondition(@RequestBody User condition) {
        return userService.findUsersByCondition(condition);
    }

    @GetMapping("/findUsersResults")
    public List<User> findUsersResults() {
        return userService.findUsersResults();
    }

    @GetMapping("/findAllResultsReuse")
    List<User> findAllResultsReuse() {
        return userService.findAllResultsReuse();
    }

    @PostMapping("/save")
    public int save(@RequestBody User user) {
        return userService.save(user);
    }

    @PostMapping("/saveUseGeneratedKeys")
    public int saveUseGeneratedKeys(@RequestBody User user) {
        return userService.saveUseGeneratedKeys(user);
    }

    @PutMapping("/updateById")
    public int updateById(@RequestBody User user) {
        return userService.updateById(user);
    }

    @DeleteMapping("/deleteById")
    public int deleteById(@RequestParam("id") Long id) {
        return userService.deleteById(id);
    }


    @PostMapping("/findConditionSelectProvider")
    public List<User> findConditionSelectProvider(@RequestBody User condition) {
        return userService.findConditionSelectProvider(condition);
    }

    @PostMapping("/saveInsertProvider")
    public int saveInsertProvider(@RequestBody User user) {
        return userService.saveInsertProvider(user);
    }

    @PostMapping("/saveInsertProviderColumns")
    public int saveInsertProviderColumns(@RequestBody User user) {
        return userService.saveInsertProviderColumns(user);
    }

    @PutMapping("/updateUpdateProvider")
    public int updateUpdateProvider(@RequestBody User user) {
        return userService.updateUpdateProvider(user);
    }

    @DeleteMapping("/deleteDeleteProvider")
    public int deleteDeleteProvider(@RequestParam("id") Long id) {
        return userService.deleteDeleteProvider(id);
    }
}
